package br.com.dreamsource.mobile.jmesql.util;

import br.com.dreamsource.mobile.jmesql.util.CharacterDataLatin1;
import java.lang.Character;

public class Character2 {
    
    public static final int MIN_CODE_POINT = 0x000000;    
    private static final int FAST_PATH_MAX = 255;
    
    private static int getPlane(int ch) {
        return (ch >>> 16);
    }
    
    public static boolean isJavaIdentifierStart(char ch) {
        return isJavaIdentifierStart((int)ch);
    }
    
    public static boolean isJavaIdentifierStart(int codePoint) {
        boolean bJavaStart = false;

        if (codePoint >= MIN_CODE_POINT && codePoint <= FAST_PATH_MAX) {
            bJavaStart = CharacterDataLatin1.isJavaIdentifierStart(codePoint);
        } else {
            int plane = getPlane(codePoint);
            switch(plane) {
            case(0):
                bJavaStart = CharacterData00.isJavaIdentifierStart(codePoint);
                break;
            case(1):
                bJavaStart = CharacterData01.isJavaIdentifierStart(codePoint);
                break;
            case(2):
                bJavaStart = CharacterData02.isJavaIdentifierStart(codePoint);
                break;
            case(3): // Undefined
            case(4): // Undefined
            case(5): // Undefined
            case(6): // Undefined
            case(7): // Undefined
            case(8): // Undefined
            case(9): // Undefined
            case(10): // Undefined
            case(11): // Undefined
            case(12): // Undefined
            case(13): // Undefined
                bJavaStart = CharacterDataUndefined.isJavaIdentifierStart(codePoint);
                break;
            case(14): 
                bJavaStart = CharacterDataOE.isJavaIdentifierStart(codePoint);
                break;
            case(15): // Private Use
            case(16): // Private Use
                bJavaStart = CharacterDataPrivateUse.isJavaIdentifierStart(codePoint);
                break;
            default:
                // the argument's plane is invalid, and thus is an invalid codepoint
                // bJavaStart remains false;
                break;
            }   
        }
        return bJavaStart;
    }

    public static boolean isJavaIdentifierPart(char ch) {
        return isJavaIdentifierPart((int)ch);
    }

    public static boolean isJavaIdentifierPart(int codePoint) {
        boolean bJavaPart = false;

        if (codePoint >= MIN_CODE_POINT && codePoint <= FAST_PATH_MAX) {
            bJavaPart = CharacterDataLatin1.isJavaIdentifierPart(codePoint);
        } else {
            int plane = getPlane(codePoint);
            switch(plane) {
            case(0):
                bJavaPart = CharacterData00.isJavaIdentifierPart(codePoint);
                break;
            case(1):
                bJavaPart = CharacterData01.isJavaIdentifierPart(codePoint);
                break;
            case(2):
                bJavaPart = CharacterData02.isJavaIdentifierPart(codePoint);
                break;
            case(3): // Undefined
            case(4): // Undefined
            case(5): // Undefined
            case(6): // Undefined
            case(7): // Undefined
            case(8): // Undefined
            case(9): // Undefined
            case(10): // Undefined
            case(11): // Undefined
            case(12): // Undefined
            case(13): // Undefined
                bJavaPart = CharacterDataUndefined.isJavaIdentifierPart(codePoint);
                break;
            case(14): 
                bJavaPart = CharacterDataOE.isJavaIdentifierPart(codePoint);
                break;
            case(15): // Private Use
            case(16): // Private Use
                bJavaPart = CharacterDataPrivateUse.isJavaIdentifierPart(codePoint);
                break;
            default:
                // the argument's plane is invalid, and thus is an invalid codepoint
                // bJavaPart remains false;
                break;
            }
        }
        return bJavaPart;
    }

    public static boolean isWhitespace(char ch) {
        return isWhitespace((int)ch);
    }

    public static boolean isWhitespace(int codePoint) {
        boolean bWhiteSpace = false;

        if (codePoint >= MIN_CODE_POINT && codePoint <= FAST_PATH_MAX) {
            bWhiteSpace =  CharacterDataLatin1.isWhitespace(codePoint);
        } else {
            int plane = getPlane(codePoint);
            switch(plane) {
            case(0):
                bWhiteSpace = CharacterData00.isWhitespace(codePoint);
                break;
            case(1):
                bWhiteSpace = CharacterData01.isWhitespace(codePoint);
                break;
            case(2):
                bWhiteSpace = CharacterData02.isWhitespace(codePoint);
                break;
            case(3): // Undefined
            case(4): // Undefined
            case(5): // Undefined
            case(6): // Undefined
            case(7): // Undefined
            case(8): // Undefined
            case(9): // Undefined
            case(10): // Undefined
            case(11): // Undefined
            case(12): // Undefined
            case(13): // Undefined
                bWhiteSpace = CharacterDataUndefined.isWhitespace(codePoint);
                break;
            case(14): 
                bWhiteSpace = CharacterDataOE.isWhitespace(codePoint);
                break;
            case(15): // Private Use
            case(16): // Private Use
                bWhiteSpace = CharacterDataPrivateUse.isWhitespace(codePoint);
                break;
            default:
                // the argument's plane is invalid, and thus is an invalid codepoint
                // bWhiteSpace remains false
                break;
            }
        }
        return bWhiteSpace;
    }

 }
 
